package com.zzb.framework.modules.log.controller;

import com.google.common.collect.Lists;
import com.zzb.framework.common.BasePage;
import com.zzb.framework.common.BaseResponse;
import com.zzb.framework.common.FrameworkException;
import com.zzb.framework.modules.log.entity.SysLogEntity;
import com.zzb.framework.modules.log.form.SysLogSearchForm;
import com.zzb.framework.modules.log.service.SysLogService;
import com.zzb.framework.modules.role.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/log")
public class SysLogController extends AbstractController {
    private static final Logger logger = LoggerFactory.getLogger(SysLogController.class);
    @Autowired
    private SysLogService sysLogService;

    /**系统配置表列表json*/
    @RequestMapping("list")
    @RequiresPermissions("sys:log:list")
    public BasePage<SysLogEntity> list(SysLogSearchForm searchForm){
        return sysLogService.queryPage(searchForm);
    }


    /**
     * 获取登录的用户信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("sys:log:info")
    public BaseResponse<SysLogEntity> info(@PathVariable("id") String id){
        SysLogEntity sysLogEntity = sysLogService.get(id);
        return BaseResponse.content(sysLogEntity);
    }


    /**系统配置表删除*/
    @PostMapping("/delete")
    @RequiresPermissions("sys:log:delete")
    public BaseResponse delete( @RequestBody String[] id){
        try {
            return sysLogService.deleteByIds(Lists.newArrayList(id));
        } catch (FrameworkException e) {
            e.printStackTrace();
            return new BaseResponse(BaseResponse.FAIL,e.getMessage());
        }
    }

}
